<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../plugins/layui/css/style.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/admin.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../plugins/zTree/css/metroStyle/metroStyle.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="../plugins/zTree/css/metroStyle/ext.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="//at.alicdn.com/t/c/font_3564966_a6tt4yhnzge.css" media="all">
    <link rel="stylesheet" href="../plugins/toastr/toastr.min.css?v=${.Config.basic.version}">

</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的资料</div>
                <div class="layui-card-body" pad15>

                    <form class="layui-form" lay-filter="form">
                        <div class="layui-form-item layui-hide">
                            <label class="layui-form-label">ID</label>
                            <div class="layui-input-block">
                                <input type="text" name="id" lay-verify="" placeholder="" autocomplete="off" class="layui-input" disabled>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">我的角色</label>
                            <div class="layui-input-inline">
                                <input type="text" name="role_names" value="" readonly class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userid" lay-verify="required" lay-verType="tips" value="" readonly class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" lay-verify="required" lay-verType="tips" autocomplete="off" placeholder="请输入昵称" class="layui-input">
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">手机</label>
                            <div class="layui-input-inline">
                                <input type="text" name="phone"  lay-verType="tips" lay-verify="phone" autocomplete="off" class="layui-input">
                            </div>
                            <label class="layui-form-label">短信通知</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" name="phone_notice" checked="" lay-skin="switch"  >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">邮箱</label>
                            <div class="layui-input-inline">
                                <input type="text" name="email" lay-verType="tips" lay-verify="email" autocomplete="off" class="layui-input">
                            </div>
                            <label class="layui-form-label">邮件通知</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" name="email_notice" checked="" lay-skin="switch"  >
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">初始页面</label>
                            <div class="layui-input-inline">
                                <select name="default_page" lay-filter="default_page" lay-verify="required" lay-search=""  >
                                    <option value="./Home/Index">数据概览</option>
                                    <option value="./Dashboard/Index">大屏</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn layui-btn-normal action-edit" lay-submit lay-filter="btn_ok">保存</button>
                            </div>
                        </div>

                    </form>

                </div>
            </div>
        </div>
    </div>
</div>


<script src="../plugins/layui/layui.js"></script>
<script src="../plugins/layui/xm-select-v1.2.4.js"></script>
<script src="../plugins/jquery/jquery-3.6.0.js?v=${.Config.basic.version}"></script>
<script src="../plugins/jquery.slimscroll.min.js"></script>
<script src="../plugins/toastr/toastr.min.js"></script>
<script src="../js/utils.js"></script>
<script src="../js/verify.js"></script>
<script src="../js/func.js?v=${.Config.basic.version}"></script>
<script>
    var net_ip = GetQueryString('net_ip');
    var slot_index = GetQueryString('slot_index');
    var level = GetQueryString('level');

    var table=null;
    var form=null;
    var laydate=null;
    var iconPicker =null;
    var Table=null;
    var sys_roles=null;
    var token = window.localStorage.getItem("token");
    var user_info=JSON.parse(window.localStorage.getItem("user_info"));
    var func_url="${.func_url}";
    var actions=[];
    var permissions=[];
    token = 'Bearer ' + token;

    layui.config({
        base: '../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','form','laydate'], function(){
        $ = layui.$;
        form = layui.form;
        table = layui.table;
        layui.form.render();

        toastr.options = {
            "closeButton": false, //是否显示关闭按钮
            "debug": false, //是否使用debug模式
            "positionClass": "toast-top-center",//弹出窗的位置
            "showDuration": "300",//显示的动画时间
            "hideDuration": "1000",//消失的动画时间
            "timeOut": "2000", //展现时间
            "extendedTimeOut": "1000",//加长展示时间
            "showEasing": "swing",//显示时的动画缓冲方式
            "hideEasing": "linear",//消失时的动画缓冲方式
            "showMethod": "fadeIn",//显示时的动画方式
            "hideMethod": "fadeOut" //消失时的动画方式
        };

        layer.load(1);
        $.ajax({
            type: 'GET',
            url: '../Api/User',
            data: {},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (data) {
                layer.closeAll();
                //console.info(data);
                if(data.phone_notice>0){
                    data.phone_notice = "on";
                }else{
                    data.phone_notice = "";
                }
                if(data.email_notice>0){
                    data.email_notice = "on";
                }else{
                    data.email_notice = "";
                }
                form.val("form", data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //layer.msg('加载用户信息失败');
                toastr.warning('加载用户信息失败');
            }
        });

        //监听提交
        form.on('submit(btn_ok)', function(data){
            var field = data.field; //获取提交的字段
            //console.info(field);
            if(field.phone_notice && field.phone_notice=="on"){
                field.phone_notice = 1;
            }else{
                field.phone_notice = 0;
            }
            if(field.email_notice && field.email_notice=="on"){
                field.email_notice = 1;
            }else{
                field.email_notice = 0;
            }

            $.ajax({
                type: 'PUT',
                url: '../Api/User/Profile',
                data: field,
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer ' + window.localStorage.getItem("token"));
                },
                dataType: "json",
                success: function (data) {
                    //console.info(data)
                    if(data.code>=0){
                        //layer.msg('保存成功');
                        toastr.success('保存成功');
                    }else{
                        layer.alert('保存失败:'+data.msg);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('保存失败');
                }
            });

        });
    });



</script>

<script src="../js/check_screen.js?v=${.Config.basic.version}"></script>

</body>

</html>